var app = angular.module('App')
.config(['$httpProvider', '$controllerProvider', function($httpProvider, $controllerProvider) {
	$httpProvider.defaults.headers.post = {'Content-Type' : 'application/x-www-form-urlencoded'};
	$controllerProvider.allowGlobals();
}])

.run(['$rootScope', '$location' , '$state','cookies',function($rootScope, $location, $state,cookies){
//监听路由事件
 
        $rootScope.$on('$stateChangeStart',
 
            function(event, toState, toParams, fromState, fromParams){
            	if(toState.name!=="login"){
                   var oChange = cookies.getCookie('userName');
                	if (oChange == '') {
                		$state.go('login');
                	}
                }
 
        })
 
}])


.config(function ($stateProvider, $urlRouterProvider) {

     $urlRouterProvider.when("", "login");

     $stateProvider
        .state("login", {
            url: "/login",
            templateUrl: "viwes/login.html",
             controller:'loginCtrl'
        })
        .state("main", {
            url: "/main",
            templateUrl: "viwes/main.html"
        })
        .state("main.houseAdm", {
            url:"/houseAdm",
            templateUrl: "viwes/houseAdm.html",
            controller:'houseAdmCtrl'
        })
        .state("main.eamic", {
            url:"/eamic",
            templateUrl: "viwes/eamic.html",
            controller:'eamicCtrl'
        })
        .state("main.risk", {
            url:"/risk",
            templateUrl: "viwes/risk.html",
            controller:'riskCtrl'
        })
        .state("main.riskManagement", {
            url:"/riskManagement",
            templateUrl: "viwes/riskManagement.html",
            controller:'riskManagementCtrl'
        })
        .state("main.tenant", {
            url:"/tenant",
            templateUrl: "viwes/tenant.html",
            controller:'tenantCtrl'
        })
      	.state("main.foundEamic", {
            url:"/foundEamic",
            templateUrl: "viwes/foundEamic.html",
            controller:'foundEamicCtrl'
        })
      
	    
        
});	            